﻿using AutoMapper;
using MediatR;
using T_vehicle.API.Application.Command.IllegalCommand;
using T_vehicle.Domain;
using T_vehicle.Infrastructure.Interfacec;

namespace T_vehicle.API.Application.CommandHandlers.IllegalCommandHandlers
{
    public class AddIllegalCommandHandlers:IRequestHandler<AddIllegalCommand,int>
    {
        private readonly IIllegalRepository illegalRepository;
        private readonly IMapper mapper;

        public AddIllegalCommandHandlers(IIllegalRepository illegalRepository, IMapper mapper)
        {
            this.illegalRepository = illegalRepository;
            this.mapper = mapper;
        }

        public async Task<int> Handle(AddIllegalCommand request, CancellationToken cancellationToken)
        {
            var Info = mapper.Map<Illegal>(request);
            Info.CreateDate = DateTime.Now;
            return await illegalRepository.AddAsync(Info);

            //var Info = new Illegal();
            //Info.IllegalTitle = request.IllegalTitle;
            //Info.LicenNumber = request.LicenNumber;                      
            //Info.Violators = request.Violators;
            //Info.ViolatorsDate = request.ViolatorsDate;
            //Info.Violations = request.Violations;
            //Info.Punish = request.Punish;
            //Info.CreateDate = DateTime.Now;
            //return await illegalRepository.AddAsync(Info);
        }
    }
}
